<template>
  <div class="go-top" v-show="scrollNow>1000" @click="GoTop">
    <img src="@/assets/GoTop.png" alt="" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      scrollNow: ''
    }
  },
  mounted(){
    window.addEventListener('scroll',this.scrollGet,true)
  },
  methods: {
    scrollGet(){
      console.log(document.body.scrollHeight)
      this.scrollNow = document.body.scrollTop || document.documentElement.scrollTop
    },
    GoTop(){
      let top = document.body.scrollTop || document.documentElement.scrollTop
      let GoT=setInterval(() => {
        document.body.scrollTop = document.documentElement.scrollTop = top -=100
        if(top<=0){
          clearInterval(GoT)
        }
      }, 10);
      }
  }
  }
</script>

<style scoped>
.go-top {
  width: 100px;
  position: fixed;
  right: 6%;
  bottom: 50%;
}
.go-top img {
  width: 100%;
}
</style>